package com.example.service.impl;

import com.example.service.RoleCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;

//AI
@Service
public class RoleCacheServiceImpl implements RoleCacheService {
    @Autowired
    private final CacheManager cacheManager;

    @Autowired
    public RoleCacheServiceImpl(CacheManager cacheManager) {
        this.cacheManager = cacheManager;
    }

    public void evictUserRoles(Long userId) {
        Cache cache = cacheManager.getCache("userRoles");
        if (cache != null) {
            cache.evict(userId);
        }
    }
}
